<template>
  <vxe-modal v-model="secReportDialog" title="发布初级报告" :mask="false" width="70vw" height="85vh" show-footer :destroy-on-close="true" show-zoom resize>
    <template #default>
      <Splitpanes>
        <Pane size="100">
          <el-scrollbar class="padding-lr-sm">
            <!-- 危急值上报 -->
            <div id="reportAlarmValueDetail">
              <!-- <el-divider content-position="left">基本信息</el-divider> -->
              <vxe-toolbar class-name="bg-grey light">
                <template #buttons>
                  <span class="text-bold text-shadow text-black margin-left-xs text-df">基本信息</span>
                </template>
              </vxe-toolbar>
              <el-descriptions :column="4" labelClassName="description-label" contentClassName="description-content" border class="margin-bottom-sm">
                <el-descriptions-item>
                  <template #label>
                    <span>病历号</span>
                  </template>
                  <span>{{ mainInfo.patNo }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>性别</span>
                  </template>
                  <span> {{ mainInfo.sex === '1' ? '男' : mainInfo.sex === '2' ? '女' : '未知' }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>年龄</span>
                  </template>
                  <span>{{ mainInfo.age+mainInfo.ageUnit }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>病人类型</span>
                  </template>
                  <span>{{ mainInfo.patTypeNa }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>科室</span>
                  </template>
                  <span>{{ mainInfo.reqDeptNa }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>样本类型</span>
                  </template>
                  <span>{{ mainInfo.sampleTypeNa }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>报告单元</span>
                  </template>
                  <span>{{ mainInfo.rptGroupNa }}</span>
                </el-descriptions-item>
              </el-descriptions>

              <!-- <el-divider content-position="left">血培养信息</el-divider> -->
              <vxe-toolbar class-name="bg-grey light">
                <template #buttons>
                  <span class="text-bold text-shadow text-black margin-left-xs text-df">血培养信息</span>
                </template>
              </vxe-toolbar>
              <el-descriptions :column="4" labelClassName="description-label" contentClassName="description-content" border class="margin-bottom-sm">
                <el-descriptions-item>
                  <template #label>
                    <span>培养瓶</span>
                  </template>
                  <span>{{ bloodCultureObj.culMediumNa }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>采样部位</span>
                  </template>
                  <span>{{ bloodCultureObj.samplingSiteNa }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>重量</span>
                  </template>
                  <span>{{ bloodCultureObj.weight }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>培养时长</span>
                  </template>
                  <span>{{ bloodCultureObj.expoTime }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>培养结果</span>
                  </template>
                  <span>{{ bloodCultureObj.result }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>标本污染</span>
                  </template>
                  <span :class="bloodCultureObj.isPollute === '1' ? 'bg-red' : ''"> {{ bloodCultureObj.isPollute === '1' ? '是' : '否' }}</span>
                </el-descriptions-item>
                <!-- <el-descriptions-item>
                  <template #label>
                    <span>菌落计数</span>
                  </template>
                  <span>{{ bloodCultureObj.strainCount }}</span>
                </el-descriptions-item> -->
                <el-descriptions-item>
                  <template #label>
                    <span>培养箱</span>
                  </template>
                  <span>{{ bloodCultureObj.instrNa }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>危急值</span>
                  </template>
                  <span :class="bloodCultureObj.isAlarm === 1 ? 'bg-red' : ''"> {{ bloodCultureObj.isAlarm === 1 ? '是' : '否' }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>瓶号</span>
                  </template>
                  <span>{{ bloodCultureObj.bottleNo }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>位置</span>
                  </template>
                  <span>{{ bloodCultureObj.posInfo }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>状态</span>
                  </template>
                  <span>{{ bloodCultureObj.state }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>开始培养时间</span>
                  </template>
                  <span>{{ bloodCultureObj.testTime }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>结束培养时间</span>
                  </template>
                  <span>{{ bloodCultureObj.resultTime }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>特殊描述</span>
                  </template>
                  <span>{{ bloodCultureObj.specialDesc }}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <span>危急值描述</span>
                  </template>
                  <span>{{ bloodCultureObj.alarmText }}</span>
                </el-descriptions-item>
                <el-descriptions-item span="24">
                  <template #label>
                    <span>培养曲线</span>
                  </template>
                  <div class="block">
                    <el-image v-if="bloodCultureObj.cultureCurveUrls" class="img-no-drag" :src="bloodCultureObj.cultureCurveUrls" />
                  </div>
                </el-descriptions-item>
              </el-descriptions>

            </div>
          </el-scrollbar>
        </Pane>
        <!-- <Pane size="30">
          <Splitpanes horizontal>
            <Pane size="70">
              <div style="position:relative;height:100%;">
                <div style="height:calc(100% - 120px - 35px)">
                  <div class="grid-container">
                    <div class="grid-item text-xs text-cut" :class="m===84?'active':''" v-for="m in 200" :key="m">{{`${m}`}}</div>
                  </div>
                </div>
              </div>
            </Pane>
            <Pane size="30">
              <div class="text-bold  margin-left-xs">
                <span class="bg-gray text-df padding-lr-xs radius">箱号</span><span style="min-width:100px !important;width:100%" class="bg-orange padding-lr-sm text-df margin-left-xs radius light">{{bloodCultureObj.posCol}}</span>
              </div>
              <div class="text-bold margin-left-xs">
                <span class="bg-gray  text-df padding-lr-xs radius">架号</span><span style="min-width:100px !important;width:100%" class="bg-blue padding-lr-sm text-df margin-left-xs radius light">{{bloodCultureObj.posRow}}</span>
              </div>
            </Pane>
          </Splitpanes>
        </Pane> -->
      </Splitpanes>
    </template>
    <template #footer>
      <div class="flex justify-end" style="margin-top:20px;">
        <vxe-button type="text" class="button-blue margin-left-xs" content="确定" @click="confirmSecReport" :loading="saveFirstReportLoading"></vxe-button>
        <vxe-button type="text" class="button-white margin-left-xs" content="取消" @click="secReportDialog=false"></vxe-button>
      </div>
    </template>
  </vxe-modal>
</template>
<script lang="ts" setup>
import { reactive, ref, defineExpose, getCurrentInstance } from 'vue';
import { IsEmpty, sortByField, formatDateTime } from '@/utils/common';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { getOptionValueByCodeGlobalOption, getOptionValueByCodeRptGroupOption } from '@/utils/SysOptionsHelper';
import { Splitpanes, Pane } from 'splitpanes';
import { saveProcessLogs } from '@/utils/BacProcessLogHelper';

let { proxy }: any = getCurrentInstance();
let bloodCultureObj = reactive({});
let mainInfo = reactive({}); //主记录病人信息
let secReportDialog = ref(false);/**控制弹窗显示与否 */
let curCulMediumObj = reactive({});/**当前选中节点 */
let saveFirstReportLoading = ref(false);/**保存初级报告 */
const options = [
  {
    value: '0',
    label: '涂片'
  },
  {
    value: '2',
    label: '转种'
  },
  {
    value: '1',
    label: '分纯'
  }
];

let allowEditRptTime = ref(false); /**允许编辑上报时间 */

defineExpose({
  initPage
});

function initPage(labMainInfo, formData, culmdmObj) {
  console.log(formData);
  secReportDialog.value = true;
  Object.assign(mainInfo, labMainInfo);
  Object.assign(bloodCultureObj, formData);
  Object.assign(curCulMediumObj, culmdmObj);
}

function getIsStaticStatusDesc(row) {
  if (row == 0) {
    return '涂片';
  } else if (row == 1) {
    return '纯分';
  } else if (row == 2) {
    return '转种';
  } else if (row == 3) {
    return '续培';
  } else {
    return '';
  }
}
/**确认发布报告 */
function confirmSecReport() {
  const datas = [];
  const data = {
    rptGroup: mainInfo.rptGroup,
    sampleda: mainInfo.sampleda + ' 00:00:00',
    sampleNo: mainInfo.sampleNo,
    testFlowNo: mainInfo.testFlowNo,
    testNodeNo: mainInfo.nodeNo,
    culCombinaNo: curCulMediumObj.cultureCombinNo,
    culMediumNo: curCulMediumObj.cultureNo,
    bloodcultureId: bloodCultureObj.id,
    isCancel: 0,
    cancelDoctor: '',
    cancelReason: ''
  };
  datas.push(data);
  const url = '/api/bac/bac-publis-first-report/batchEditPublisFirstReport';
  saveFirstReportLoading.value = true;
  proxy.$http
    .post(url, datas)
    .then((res: any) => {
      VxeMessage('发布成功', VxeNotifyType.success);
      saveFirstReportLoading.value = false;

      try {
        /* 记录过程记录 */
        const a = localStorage.getItem('userInfo');
        const b = JSON.parse(a);
        const cntStr = [
          !IsEmpty(bloodCultureObj.culMediumNa) ? '培养瓶:' + bloodCultureObj.culMediumNa + '' : '',
          !IsEmpty(bloodCultureObj.samplingSiteNa) ? '采样部位:' + bloodCultureObj.samplingSiteNa + '' : '',
          !IsEmpty(bloodCultureObj.weight) ? '重量:' + bloodCultureObj.weight + '' : '',
          !IsEmpty(bloodCultureObj.isPositive) ? '是否阳性:' + (bloodCultureObj.samplingSiteNa === 1 ? '是' : '否') + '' : '',
          !IsEmpty(bloodCultureObj.result) ? '鉴定结果:' + bloodCultureObj.result + '' : '',
          !IsEmpty(bloodCultureObj.specialDesc) ? '特殊描述:' + bloodCultureObj.specialDesc + '' : '',
          !IsEmpty(bloodCultureObj.isAlarm) ? '危急值:' + (bloodCultureObj.isAlarm === 1 ? '是' : '否') + '' : '',
          !IsEmpty(bloodCultureObj.alarmText) ? '危急值描述:' + bloodCultureObj.alarmText + '' : '',
          !IsEmpty(bloodCultureObj.isPollute) ? '标本污染:' + (bloodCultureObj.isPollute === 1 ? '是' : '否') + '' : '',
          !IsEmpty(bloodCultureObj.instrNa) ? '培养箱:' + bloodCultureObj.instrNa + '' : '',
          !IsEmpty(bloodCultureObj.barcode) ? '容器条码:' + bloodCultureObj.barcode + '' : '',
          !IsEmpty(bloodCultureObj.bottleNo) ? '瓶号:' + bloodCultureObj.bottleNo + '' : '',
          !IsEmpty(bloodCultureObj.posInfo) ? '位置:' + bloodCultureObj.posInfo + '' : '',
          !IsEmpty(bloodCultureObj.state) ? '状态:' + bloodCultureObj.state + '' : '',
          !IsEmpty(bloodCultureObj.testTime) ? '开始培养时间:' + bloodCultureObj.testTime + '' : '',
          !IsEmpty(bloodCultureObj.resultTime) ? '结束培养时间:' + bloodCultureObj.resultTime + '' : '',
          !IsEmpty(bloodCultureObj.destructionTime) ? '销毁时间:' + bloodCultureObj.destructionTime + '' : '',
          !IsEmpty(bloodCultureObj.expoTime) ? '培养时长:' + bloodCultureObj.expoTime + '' : ''
        ].filter(Boolean) // 过滤掉空字符串
          .join('\n');
        const strainNameStr = !IsEmpty(bloodCultureObj.culMediumNa) ? '培养瓶:' + bloodCultureObj.culMediumNa + '' : '';
        const processLogData = {
          strainId: null,
          strainNo: null,
          strainName: strainNameStr,
          maininfoId: mainInfo.id,
          wkFlwId: null,
          wkFlwNodeId: null,
          rptGroup: mainInfo.rptGroup,
          sampleda: formatDateTime(mainInfo.sampleda, 'yyyy-MM-dd 00:00:00'),
          sampleNo: mainInfo.sampleNo,
          testFlowNo: bloodCultureObj.testFlowNo,
          testNodeNo: 'YQPY',
          content: `【${formatDateTime(new Date(), 'yyyy-MM-dd hh:mm:ss')}】操作人:【${IsEmpty(b.realname) ? '' : b.realname}】发布初级报告\n${cntStr}`,
          operatorDoctor: IsEmpty(b.username) ? '' : b.username
        };
        saveProcessLogs(processLogData);
      } catch (error) {
        console.log('错误', error);
      }
    })
    .catch((err: any) => {
      saveFirstReportLoading.value = false;
      VxeMessage('发布失败', VxeNotifyType.error);
    });
}
</script>

<style lang="scss" scoped>
:deep(.vxe-modal--wrapper) {
  z-index: 10 !important;
}
:deep(.el-descriptions__label) {
  width: 120px;
}
:deep(.el-descriptions__content) {
  color: #000;
}
:deep(.vxe-cell) {
  padding-left: 5px;
}
.tableForm {
  height: calc(100% - 80px);
  .tableBody {
    height: 75%;
  }
  .formBody {
    height: 25%;
    padding: 0 25px;
    :deep(.vxe-form--item) {
      margin-right: 15px;
    }
  }
}
/* 定义父容器的样式 */
.grid-container {
  display: grid;
  /* 行列的间距（可根据需要调整） */
  gap: 2px;
  /* 根据需要设定最小的列宽和行高 */
  ///min-width: 10px;
  //min-height: 10px;
  //grid-template-columns: repeat(3, 1fr);
  /* 自动计算列数和行数 */
  grid-template-columns: repeat(10, auto);
  //grid-template-rows: repeat(auto-fit, minmax(min-height, auto));
}

/* 定义子项的样式 */
.grid-item {
  /* 这里设置了子项的基础样式 */
  background-color: #e2e2e2; //#4caf50
  color: white;
  text-align: center;
  padding: 2px;
  border-radius: 0px;
  cursor: pointer;
  //font-size: clamp(0.1rem, 0.5rem, 2rem); /* 根据容器大小动态调整字体大小 */
  //text-align: center;
}
.active {
  background-color: #4caf50;
}
</style>
